{extend name="personcentor/information"}
{block name="main"}
<div class="col-main">
    <div class="main-wrap">
            <div style="height:100px"></div>
            <div style="margin-left:8%;">

            <table class="table table-hover " >
             <caption><h3 style="margin-left:40%;">我所发布的房源</h3></caption>
                <tr>
                    <th style='text-align: center;'>房屋名字</th>
                    <th style='text-align: center;'>房屋地址</th>
                    <th style='text-align: center;'>房屋价格(天)</th>
                    <th style='text-align: center;'>房屋图片</th>
                    <th style='text-align: center;'>联系人</th>
                    <th style='text-align: center;'>创建时间</th>
                    <th style='text-align: center;'>审核</th>
                    <th style='text-align: center;'>操作</th>
                </tr>
                {volist name="houseresource" id="vo"}
                <input class="input" type="hidden" value="{$vo.user_id}"/>
                <tr align="middle">
                    <td>{$vo.house_name}</td>
                    <td>{$vo.house_address}</td>
                    <td>{$vo.houseprice}</td>
                    <td><img src="/uploads/housepic/{:str_replace('\','/',$vo.house_pic)}" style="width:100px;height:30px;"></td>
                    <td style="cursor:pointer;">[<a data-toggle="modal" data-target=".bs-example-modal-sm" id="goods">{$vo.link_name}</a>]</td>
                    <td>{$vo.createtime}</td>
                    <td>{if condition="$vo.checking eq 0"}待审核
                        {elseif condition="$vo.checking eq 1" /}审核通过
                        {else}审核不通过
                        {/if}
                    </td>
                    <td>
                        <a type="button" class="btn btn-info" href="{:url('index/business/edit',['id'=>$vo.id])}" ><span class="glyphicon glyphicon-wrench"></span></a>
                        <div type="button" data-id="{$vo.id}" class="btn btn-danger del-btn"><span class="glyphicon glyphicon-trash"></span></div>
                    </td>
                </tr>
                {/volist}

            </table>
            </div>

    </div>
</div>

<!-- 模态框开始 -->

<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm" role="document">

        <div class="modal-content">
            <div style="margin-left:10px;">
                <h4>联系人信息</h4>
                <hr/>
                <p class="usertype"></p>
                <p class="linkname"></p>
                <p class="linkphone"></p>
                <p class="name_company"></p>
                <p class="id_reg"></p>
            </div>
        </div>
    </div>
</div>

<!-- 模态框结束 -->


<script>
    //获取商家信息
    $(function(){
        $('#goods').click(function(){
           var link_name = $('#goods').html();
           var user_id =$('.input').val();
           console.log(link_name,user_id);
           $.ajax({
               url : '/business/goodsdetail',
               type : 'post',
               data : {'link_name' : link_name , 'user_id':user_id},
               dataType:'json',
               success: function(data){

                   $('.linkname').html('联系人:'+data['link_name']);
                   $('.linkphone').html('联系电话:'+data['link_phone']);

                   if(data['usertype']==0){
                       $('.name_company').html('身份证姓名:'+data['name_company']);
                   }else{
                       $('.name_company').html('公司名称:'+data['name_company']);
                   }

                   if(data['usertype']==0){
                       $('.id_reg').html('身份证号:'+data['id_reg']);
                   }else{
                       $('.id_reg').html('营业执照号:'+data['id_reg']);
                   }

                   if(data['usertype']==0){
                       $('.usertype').html('用户类型:个人');
                   }else{
                       $('.usertype').html('用户类型:商家');
                   }

               },
               error: function(){
                   alert('ajax请求失败');
               }
           })
        })



        //删除商品信息
        $('.del-btn').click(function(){

            var ac_id = $(this).attr('data-id');

            if(confirm('你确定要 [ 删除 ] 该用户么?')){
                var obj = $(this).parents('tr');
              console.log(obj);
                delAjax(ac_id,obj);   //调用执行ajax删除
            }

        })

        //执行删除操作
        function delAjax(id,obj)
        {

            $.ajax({
                type : 'delete' ,
                url : '/business/'+id ,
                dataType : 'json' ,
                success : function (data){
                    if(data.status){
                       alert(data.info);
                        //将点击的节点删除掉
                        obj.remove();
                    }else{
                        alert(data.info);
                    }
                },
                error : function () {
                    alert('请求失败');

                }

            });
        }

    })
</script>


{/block}